<template>
  <div class="app-container">
    <UserInfoForm ref="UserRef" disabledUserName picture :value="userInfo" />
    <div class="tools">
      <el-button stype="primary" @click="editClick">保&nbsp;&nbsp;存</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import UserInfoForm from "@/components/UserInfoForm/index.vue";
import { useUserStore } from "@/store";

defineOptions({
  name: "",
});

const store = useUserStore();
const userInfo = Object.assign({}, store.user);

const UserRef = ref<InstanceType<typeof UserInfoForm>>();

const editClick = async () => {
  await UserRef.value?.editUser();
  if (userInfo.password) {
    store.logout();
  }
};
</script>

<style lang="scss" scoped>
.tools {
  display: flex;
  justify-content: center;
}

.tools .el-button {
  min-width: 9rem;
  min-height: 2.5rem;
  font-size: 1rem;
}
</style>
